#include "Dv.h"
#include <fbzmq/zmq/Zmq.h>
#include <thrift/lib/cpp2/protocol/Serializer.h>
#include <openr/if/gen-cpp2/KvStore_types.h>

//using apache::thrift::CompactSerializer;
using namespace fbzmq;

namespace openr {
Dv::Dv(
    std::string myNodeName,
    const DecisionPubUrl& decisionPubUrl,
    const KvStoreLocalCmdUrl& storeCmdUrl,
    const folly::Optional<std::string>& dvRepUrl,
    fbzmq::Context& zmqContext
)
: OpenrEventLoop(
          myNodeName, thrift::OpenrModuleType::FIB, zmqContext, dvRepUrl),
myNodeName_(std::move(myNodeName)),
decisionPubUrl_(decisionPubUrl),
storeCmdUrl_(storeCmdUrl)
{
    fbzmq::Socket<ZMQ_REQ, fbzmq::ZMQ_CLIENT> storeReq(zmqContext);
    const auto reqConnect = storeReq.connect(fbzmq::SocketUrl{storeCmdUrl_});

    const thrift::Value thriftVal(
        apache::thrift::FRAGILE,
        1,
        "r0",
        folly::sformat("myval"),
        Constants::kTtlInfinity,
        0,
        generateHash(1, "r0", std::string("myval"))
    );
    thrift::Request thriftReq;
    thriftReq.cmd = thrift::Command::KEY_SET;
    thriftReq.keySetParams.keyVals.emplace(folly::sformat("mykey"), thriftVal);
    apache::thrift::CompactSerializer serializer;
    storeReq.sendThriftObj(thriftReq, serializer);
}

Dv::~Dv()
{
}
}